<#assign base=request.contextPath>
<!DOCTYPE html> 
<html>
	<head>
		<title>${title}</title>
		<meta charset="utf-8">
		<#include "common/reference.ftl"/>
		<#include "common/ligerui.ftl"/>
		<script type="text/javascript">
		<!--
			$(function(){
				var treeMenus = $('#tree_menus').ligerTree({ 
												 url:'${base}/role/getRoleMenus/${roleId}',
												 textFieldName:'menuName',
												 idFieldName:'menuId',
												 parentIDFieldName:'parentId',
												 checkbox:true,
												 onSuccess: function() {
                                                     f_selectNode("1,2,3,4,5,6,7,8,9");
                                                 }
											});

                function f_selectNode(str) {
                                str = "," + str + ",";
                                var parm = function(data) {
                                    //alert("," + data.Id + ",");
                                    if (str.indexOf("," + data.Id + ",") != -1)
                                    { return true; } else { return false }
                                };
                                treeMenus.selectNode(parm);
                            };
				$('#btnSave').click(function(){
					var selectMenus = treeMenus.getChecked();
					var len = selectMenus.length;
					var menuIds = [];
					for(var i = 0; i < len; i++){
						var it = selectMenus[i].data;
						var l = menuIds.length;
						var exist = false;
						for(var j=0; j < l; j++){
							if(it.parentId == menuIds[j]){
								exist = true;
								break;
							}
						}
						menuIds.push(it.menuId);
						if(!exist){
							menuIds.push(it.parentId);
						}
					}
					$.ajax({
						url:'${base}/role/submitRoleMenus',
						type:'POST',
						data:{roleId:${roleId},menuIds:menuIds},
						dataType:'json',
						success:function(rst){
							layer.alert(rst.message,{skin:'layui-layer-lan',closeBtn:0});
						}
					});
				});
			});
		//-->
		</script>
	</head>
	<body class="${configs["skinName"]}">
		<div class="page-content">
			<div class="row">
				<#include "common/breadcrumb.ftl">
				<form id="form" role="form" class="form-horizontal" method="post" action="${base}/${form_action}">
					<div class="col-xs-12">
						<div class="widget-box">
							<div class="widget-header header-color-blue2">
								<h5 class="lighter">
									<i class="fa fa-tree"></i>
									菜单列表
								</h5>
								<div class="widget-toolbar no-border">
									<button id="btnSave" class="btn btn-xs btn-purple" type="button">
										<i class="icon-save"></i>
										保 存
									</button>
								</div>
							</div>
							<div class="widget-body">
								<div id="tree_menus"></div>
							</div>
						</div>
					</div>
				</form>
			</div>
		</div>
	</body>
</html>